package com.cicigodd.brick.plug.common.error;

import com.cicigodd.brick.plug.common.response.ResponseRenderUtil;
import com.cicigodd.brick.plug.common.response.ResultGenerator;
import org.springframework.web.servlet.View;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 当请求404的时候返回的错误界面
 *
 * @author cicigodd
 * @date 2022/09/23 08:42:00
 */
public class ErrorStaticJsonView implements View {

    @Override
    public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        if (response.isCommitted()) {
            // response已经提交不能响应
            return;
        }
        ResponseRenderUtil.renderJsonResponse(response, ResultGenerator.foundFailResult());
    }

    @Override
    public String getContentType() {
        return "text/html";
    }

}